﻿//using System;
//using System.Collections.Generic;
//using System.Data;
//using System.Data.SqlClient;
//using System.Linq;
//using System.Text;
//using System.Threading.Tasks;

//namespace RepositoryFramework.ADO
//{
//	/// <summary>
//	/// Class <see cref="GenericRepository"/> define generic repository
//	/// </summary>
//	public abstract class GenericRepository
//	{
//		#region Methods

//		/// <summary>
//		/// Processes the command to data table.
//		/// </summary>
//		/// <param name="unitOfWork">The unit of work.</param>
//		/// <param name="command">The command.</param>
//		/// <param name="tableName">Name of the table.</param>
//		/// <returns></returns>
//		protected DataTable ExecuteToDataTable(IUnitOfWork unitOfWork, string tableName)
//		{
//			command.Connection = unitOfWork.Connection;
//			command.Transaction = unitOfWork.Transaction;
//			return ExecuteToDataTable(command, tableName);
//		}

//		/// <summary>
//		/// Executes the scalar.
//		/// </summary>
//		/// <param name="unitOfWork">The unit of work.</param>
//		/// <param name="command">The command.</param>
//		/// <returns></returns>
//		protected object ExecuteScalar(IUnitOfWork unitOfWork, SqlCommand command)
//		{
//			command.Connection = unitOfWork.Connection;
//			command.Transaction = unitOfWork.Transaction;
//			var result = command.ExecuteScalar();
//			unitOfWork.Commit();
//			return result;
//		}

//		/// <summary>
//		/// Executes command to data table.
//		/// </summary>
//		/// <param name="command">The command.</param>
//		/// <returns></returns>
//		protected DataTable ExecuteToDataTable(SqlCommand command)
//		{
//			return ExecuteToDataTable(command, string.Empty);
//		}

//		/// <summary>
//		/// Executes command to data table.
//		/// </summary>
//		/// <param name="command">The command.</param>
//		/// <param name="tableName">Name of the table.</param>
//		/// <returns></returns>
//		protected DataTable ExecuteToDataTable(SqlCommand command, string tableName)
//		{
//			using (SqlDataReader reader = command.ExecuteReader())
//			{
//				var table = new DataTable(tableName);
//				table.Load(reader);
//				return table;
//			}
//		}

//		/// <summary>
//		/// Create command.
//		/// </summary>
//		/// <param name="commandText">The command text.</param>
//		/// <param name="filter">The filter.</param>
//		/// <returns></returns>
//		protected SqlCommand GetCommand<T>(string commandText, T filter) where T : IBaseFilter
//		{
//			var command = new SqlCommand(commandText);
//			command.CommandType = CommandType.StoredProcedure;

//			var parameters = filter.GetSqlParameters();
//			foreach (NameValue<string, object> item in parameters)
//			{
//				var value = item.Value;
//				if (value is int[])
//				{
//					value = ((int[])value).ToSqlParameter();
//				}
//				command.Parameters.Add(new SqlParameter("@" + item.Name, value));
//			}

//			return command;
//		}

//		#endregion
//	}
//	}
//}
